/*
 * $Id: GarbageFreeCharacterSequenceFormatter.java 66 2013-01-06 10:16:51Z vladimirow@mail.ru $
 * $HeadURL: http://ultralog.googlecode.com/svn/ultralog/tags/release-0.1/src/java/com/google/code/ultralog/formatter/gfree/GarbageFreeCharacterSequenceFormatter.java $
 *
 * This file is a part of ultralog project (http://code.google.com/p/ultralog/).
 * Released under New BSD License.
 */
package com.google.code.ultralog.formatter.gfree;

import com.google.code.ultralog.formatter.ReferenceFormatter;
import com.google.code.ultralog.utils.CharacterOutputStream;
import com.google.code.ultralog.utils.CharacterSequence;

/**
 * Garbage free implementation of {@link ReferenceFormatter} interface that
 * formats values of {@link CharacterSequence} type.
 *
 * @author Mikhail Vladimirov
 */
public class GarbageFreeCharacterSequenceFormatter
    implements ReferenceFormatter <CharacterSequence>
{
    /**
     * Singleton instance of the formatter.
     */
    public final static GarbageFreeCharacterSequenceFormatter INSTANCE =
        new GarbageFreeCharacterSequenceFormatter ();

    private GarbageFreeCharacterSequenceFormatter ()
    {
        // Do nothing
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void format (CharacterSequence value, CharacterOutputStream output)
    {
        if (output == null)
            throw new IllegalArgumentException ("Output is null");

        if (value != null)
            output.write (value, 0, value.getLength ());
        else
            output.write ("null", 0, 4);
    }
}
